package org.leetcode.easy.leetcode459;

import java.util.HashSet;
import java.util.Set;

public class Solution
{
    public boolean repeatedSubstringPattern(String s)
    {

        int length = s.length();

        Set<String> set = new HashSet<>();

        int splitLength = 0;
        while (splitLength<=length/2)
        {
            if (set.size()==1)
            {
                return true;
            }

            set.clear();

            splitLength++;

            if (length%splitLength>0)
            {
                continue;
            }
            for (int i = 0; i < length; i+=splitLength) {
                String substring = s.substring(i, i + splitLength);
                set.add(substring);
            }

        }

        return false;
    }

    public static void main(String[] args) {
        String  str ="abcabcabcabc";

//        String substring = str.substring(0, 3);
//        String substring1 = str.substring(3, 6);
//        System.out.println(substring);
//        System.out.println(substring1);

        Solution solution = new Solution();
        boolean b = solution.repeatedSubstringPattern(str);
        System.out.println(b);

    }
}
